function jsonDateFormat(date) {//json日期格式转换为正常格式(月份-日期)
    try {
        if (date == '') return "";
        var time = date.time;
        var date = new Date(date.time);
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
//	        var hours = date.getHours();
//	        var minutes = date.getMinutes();
//	        var seconds = date.getSeconds(); 
        // return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;


        var now = new Date();
        var daff = now.getTime() - time;


        var nowYear = now.getFullYear();
        var nowMonth = now.getMonth() + 1 < 10 ? "0" + (now.getMonth() + 1) : now.getMonth() + 1;
        var nowDay = now.getDate() < 10 ? "0" + now.getDate() : now.getDate();
        if (date.getFullYear() == nowYear && month == nowMonth) {
            /*if(day==nowDay){
                return  "今天 ";
            }else if(day==nowDay-1){
                return  "昨天 " ;
            }else if(day==nowDay-2){
                return  "前天";
            }else if(day==nowDay+1){
                return  "明天";
            }*/
        }
        return month + "-" + day;
    } catch (ex) {
        return "";
    }
}

function jsonDateFormat2(date) {//json日期格式转换为正常格式(年份-月份-日期)
    try {
        if (date == '') return "";
        var time = date.time;
        var date = new Date(date.time);
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
//	        var hours = date.getHours();
//	        var minutes = date.getMinutes();
//	        var seconds = date.getSeconds(); 
        // return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;


        var now = new Date();
        var daff = now.getTime() - time;


        var nowYear = now.getFullYear();
        var nowMonth = now.getMonth() + 1 < 10 ? "0" + (now.getMonth() + 1) : now.getMonth() + 1;
        var nowDay = now.getDate() < 10 ? "0" + now.getDate() : now.getDate();
        if (date.getFullYear() == nowYear && month == nowMonth) {
            if (day == nowDay) {
                return "今天 ";
            } else if (day == nowDay - 1) {
                return "昨天 ";
            } else if (day == nowDay - 2) {
                return "前天";
            } else if (day == nowDay + 1) {
                return "明天";
            }
        }
        return year + "-" + month + "-" + day;
    } catch (ex) {
        return "";
    }
}

function jsonDateFormat5(date) {//json日期格式转换为正常格式(年份-月份-日期)
    try {
        if (date == '') return "";
        var time = date.time;
        var date = new Date(date.time);
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
//	        var hours = date.getHours();
//	        var minutes = date.getMinutes();
//	        var seconds = date.getSeconds(); 
        // return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;


        var now = new Date();
        var daff = now.getTime() - time;


        var nowYear = now.getFullYear();
        var nowMonth = now.getMonth() + 1 < 10 ? "0" + (now.getMonth() + 1) : now.getMonth() + 1;
        var nowDay = now.getDate() < 10 ? "0" + now.getDate() : now.getDate();
        /* if(date.getFullYear()==nowYear&&month==nowMonth){
             if(day==nowDay){
                 return  "今天 ";
             }else if(day==nowDay-1){
                 return  "昨天 " ;
             }else if(day==nowDay-2){
                 return  "前天";
             }else if(day==nowDay+1){
                 return  "明天";
             }
         }*/
        return year + "-" + month + "-" + day;
    } catch (ex) {
        return "";
    }
}

function jsonDateFormat3(date) {//json日期格式转换为正常格式(月份-日期 HH:mm)
    try {
        if (date == '') return "";
        var time = date.time;
        var date = new Date(date.time);
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
//	        var seconds = date.getSeconds(); 
        // return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;


        var now = new Date();
        var daff = now.getTime() - time;


        var nowYear = now.getFullYear();
        var nowMonth = now.getMonth() + 1 < 10 ? "0" + (now.getMonth() + 1) : now.getMonth() + 1;
        var nowDay = now.getDate() < 10 ? "0" + now.getDate() : now.getDate();
        /*if(date.getFullYear()==nowYear&&month==nowMonth){
            if(day==nowDay){
                return  "今天 ";
            }else if(day==nowDay-1){
                return  "昨天 " ;
            }else if(day==nowDay-2){
                return  "前天";
            }else if(day==nowDay+1){
                return  "明天";
            }
        }*/
        return /*year + "-" + */month + "-" + day + " " + hours + ":" + minutes;
    } catch (ex) {
        return "";
    }
}

function jsonDateFormat4(date) {//json日期格式转换为正常格式(年份-月份-日期 HH:mm)
    try {
        if (date == '') return "";
        var time = date.time;
        var date = new Date(date.time);
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
//	        var seconds = date.getSeconds(); 
        // return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;


        var now = new Date();
        var daff = now.getTime() - time;


        var nowYear = now.getFullYear();
        var nowMonth = now.getMonth() + 1 < 10 ? "0" + (now.getMonth() + 1) : now.getMonth() + 1;
        var nowDay = now.getDate() < 10 ? "0" + now.getDate() : now.getDate();
        /*if(date.getFullYear()==nowYear&&month==nowMonth){
            if(day==nowDay){
                return  "今天 ";
            }else if(day==nowDay-1){
                return  "昨天 " ;
            }else if(day==nowDay-2){
                return  "前天";
            }else if(day==nowDay+1){
                return  "明天";
            }
        }*/
        return year + "-" + month + "-" + day + " " + hours + ":" + minutes;
    } catch (ex) {
        return "";
    }
}

function jsonDateFormat6(date) {//json日期格式转换为正常格式(年份-月份-日期 HH:mm:ss)
    try {
        if (date == '') return "";
        var time = date.time;
        var date = new Date(date.time);
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds();
        // return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;


        var now = new Date();
        var daff = now.getTime() - time;


        var nowYear = now.getFullYear();
        var nowMonth = now.getMonth() + 1 < 10 ? "0" + (now.getMonth() + 1) : now.getMonth() + 1;
        var nowDay = now.getDate() < 10 ? "0" + now.getDate() : now.getDate();
        /*if(date.getFullYear()==nowYear&&month==nowMonth){
            if(day==nowDay){
                return  "今天 ";
            }else if(day==nowDay-1){
                return  "昨天 " ;
            }else if(day==nowDay-2){
                return  "前天";
            }else if(day==nowDay+1){
                return  "明天";
            }
        }*/
        return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
    } catch (ex) {
        return "";
    }
}

function val(_forentity) {
    var rtn = true;
    $("input[forentity=" + _forentity + "]").each(function () {
        if ($(this).attr('required') != undefined && ($(this).attr('required') == 'required' || $(this).attr('required') == 'true')) {
            //alert($(this).val())
            if ($(this).val() == '') {
                alert($(this).attr('placeholder'));
                rtn = false;
                return false;
            }
        }
    });
    return rtn;
}

$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};


/**参数说明：
 * 根据长度截取先使用字符串，超长部分追加…
 * str 对象字符串
 * len 目标字节长度
 * 返回值： 处理结果字符串
 */
function cutString(str, len) {
    //length属性读出来的汉字长度为1
    if (str.length * 2 <= len) {
        return str;
    }
    var strlen = 0;
    var s = "";
    for (var i = 0; i < str.length; i++) {
        s = s + str.charAt(i);
        if (str.charCodeAt(i) > 128) {
            strlen = strlen + 2;
            if (strlen >= len) {
                return s.substring(0, s.length - 1) + "...";
            }
        } else {
            strlen = strlen + 1;
            if (strlen >= len) {
                return s.substring(0, s.length - 2) + "...";
            }
        }
    }
    return s;
}

/**参数说明：
 * 根据长度截取先使用字符串，超长部分追加…
 * str 对象字符串
 * len 目标字节长度
 * 返回值： 处理结果字符串
 */
function cutString2(str, len) {
    //length属性读出来的汉字长度为1
    if (str.length * 2 <= len) {
        return str;
    }
    var strlen = 0;
    var s = "";
    for (var i = 0; i < str.length; i++) {
        s = s + str.charAt(i);
        if (str.charCodeAt(i) > 128) {
            strlen = strlen + 2;
            if (strlen >= len) {
                return s.substring(0, s.length);
            }
        } else {
            strlen = strlen + 1;
            if (strlen >= len) {
                return s.substring(0, s.length);
            }
        }
    }
    return s;
}


/*
 * 处理浏览器前进后退。当弹出层的时候，避免浏览器后退造成页面关闭
 * 在通过div展示层的时候，需要增加history.pushState({}, document.title, '#addQuestion');
 * 页面的div需要增加mui-content 样式，退回的主div需要增加main样式
 */
var fnHashTrigger = function () {
    if (location.hash == '') {
        $(".mui-content").hide();
        $(".main").show();
    }

};
if (history.pushState) {
    if (location.hash) {
        fnHashTrigger();
        history.replaceState(null, document.title, "#");
    }
    window.addEventListener("popstate", function () {
        fnHashTrigger();
    });
}


function toDate(str) {
    str = str.replace(/-/g, "/");
    var sd = str.split("/");
    return new Date(sd[0], sd[1], sd[2]);
}
 